home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / win / c / stsbarc.exe / SBTEST.C < prev    next >
Text File  |  1991-10-07  |  16KB  |  446 lines

  1. //===========================================================================
  2. //
  3. //  Program          : SBTEST.C
  4. //  Version          : 1.2.0
  5. //  Operating System : DOS / Windows 3.0 / Microsoft C 6.0
  6. //  Author           : Jean-Marc Krikorian
  7. //                     525 Sandy Lane 
  8. //                     Libertyville, IL  60048 
  9. //                     (708) 816-3314 
  10. // 
  11. //  Copyright 1991 Jean-Marc Krikorian. All Rights Reserved.
  12. // 
  13. //===========================================================================
  14.  
  15. #include "windows.h"  
  16. #include "sbtest.h"  
  17. #include "stsbar.ext"
  18.  
  19. #define ID_STATUSBAR 2000
  20.  
  21. HANDLE hInst;
  22. HWND   hWndStatusBar = 0;
  23. HMENU  hMenu = 0;
  24. WORD   wTextAttributes = 0;
  25. WORD   wCurrentFaceColor = 0;
  26. WORD   wCurrentFaceStyle = 0;
  27. WORD   wCurrentTextColor = 0;
  28. WORD   wCurrentTextFont = 0;
  29. BOOL   bStatusBarVisible = FALSE;
  30. WORD   ypos = 0;
  31.  
  32. HANDLE hLib = NULL;  // stores the handle to the Status Bar DLL 
  33.  
  34. int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  35. {
  36.   MSG msg;                  
  37.  
  38.   if (!hPrevInstance)            
  39.       if (!InitApplication(hInstance)) 
  40.         return (FALSE);        
  41.  
  42.   if (!InitInstance(hInstance, nCmdShow))
  43.       return (FALSE);
  44.  
  45.   while (GetMessage(&msg, NULL, NULL,    NULL)) 
  46.   {
  47.       TranslateMessage(&msg);    
  48.       DispatchMessage(&msg);    
  49.   }
  50.  
  51.   return (msg.wParam);    
  52. }
  53.  
  54. BOOL InitApplication(HANDLE hInstance)
  55. {
  56.   WNDCLASS  wc;
  57.  
  58.   wc.style         = NULL;                 
  59.   wc.lpfnWndProc   = MainWndProc;    
  60.   wc.cbClsExtra    = 0;               
  61.   wc.cbWndExtra    = 0;               
  62.   wc.hInstance     = hInstance;        
  63.   wc.hIcon         = LoadIcon(hInstance, "SBTestIcon");
  64.   wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  65.   wc.hbrBackground = GetStockObject(WHITE_BRUSH); 
  66.   wc.lpszMenuName  = "SBTestMenu";   
  67.   wc.lpszClassName = "SBTestWClass"; 
  68.  
  69.   return (RegisterClass(&wc));
  70. }
  71.  
  72. BOOL InitInstance(HANDLE hInstance, int nCmdShow)
  73. {
  74.   HWND   hWnd;
  75.  
  76.   hInst = hInstance;
  77.  
  78.   hWnd = CreateWindow("SBTestWClass",                
  79.                       "Status Bar Test Application",   
  80.                       WS_OVERLAPPEDWINDOW,            
  81.                       CW_USEDEFAULT,                  
  82.                       CW_USEDEFAULT,                  
  83.                       CW_USEDEFAULT,                  
  84.                       CW_USEDEFAULT,                  
  85.                       NULL,                           
  86.                       NULL,                           
  87.                       hInstance,                      
  88.                       NULL);
  89.  
  90.   if (!hWnd)
  91.     return (FALSE);
  92.  
  93.   hLib = LoadLibrary("STSBAR.DLL");
  94.  
  95.   ypos = 10;
  96.  
  97.   // Create the status bar window
  98.   hWndStatusBar = CreateWindow("StatusBarClass",
  99.                                NULL,
  100.                                WS_CHILD | SBS_BOTTOM | WS_VISIBLE,
  101.                                0,ypos,0,0,
  102.                                hWnd,
  103.                                ID_STATUSBAR,
  104.                                hInst,
  105.                                NULL);
  106.  
  107.   if (!hWndStatusBar)
  108.   {
  109.     FreeLibrary(hLib);
  110.     return (FALSE);
  111.   }
  112.  
  113.   // this is now the default if the monitor is VGA or better
  114. //  SendMessage(hWndStatusBar, SBM_FACESTYLE, 0, (LONG)SBFS_3DFACE);
  115.   wCurrentFaceStyle = IDM_SB3DFACE;
  116.   CheckMenuItem(hMenu, wCurrentFaceStyle, MF_CHECKED);
  117.  
  118.   // this is now the default if the monitor is VGA or better
  119. //  SendMessage(hWndStatusBar, SBM_FACECOLOR, 0, (LONG)SBCLR_GRAY);
  120.   wCurrentFaceColor = IDM_SBGRAYFACE;
  121.   CheckMenuItem(hMenu, wCurrentFaceColor, MF_CHECKED);
  122.  
  123.   SendMessage(hWndStatusBar, SBM_TEXTCOLOR, 0, (LONG)SBCLR_BLACK);
  124.   wCurrentTextColor = IDM_SBBLACKTEXT;
  125.   CheckMenuItem(hMenu, wCurrentTextColor, MF_CHECKED);
  126.  
  127.   wCurrentTextFont = IDM_SBDEFAULTSYSTEM;
  128.   CheckMenuItem(hMenu, wCurrentTextFont, MF_CHECKED);
  129.  
  130.   bStatusBarVisible = TRUE;
  131.   CheckMenuItem(hMenu, IDM_SBSHOW, MF_CHECKED);
  132.  
  133.   ShowWindow(hWndStatusBar, SW_SHOW);
  134.  
  135.   ShowWindow(hWnd, nCmdShow);  
  136.   UpdateWindow(hWnd);          
  137.  
  138.   return (TRUE);    
  139. }
  140.  
  141. long FAR PASCAL MainWndProc(HWND hWnd, unsigned message, WORD wParam, LONG lParam)
  142. {
  143.   static char    SText[80];
  144.          LOGFONT lf;
  145.  
  146.   switch (message)
  147.   {
  148.     case WM_CREATE:
  149.       hMenu = GetMenu(hWnd);
  150.       wsprintf(SText, "%s%d", (LPSTR)"This is the Status Bar...", GetWindowWord(hWnd, GWW_HINSTANCE));
  151.       return 0;
  152.  
  153.       case WM_COMMAND:
  154.     {
  155.       switch (wParam)
  156.       {
  157.           case IDM_SBSHOW:
  158.           bStatusBarVisible = TRUE;
  159.           CheckMenuItem(hMenu, IDM_SBSHOW, MF_CHECKED);
  160.           CheckMenuItem(hMenu, IDM_SBHIDE, MF_UNCHECKED);
  161.           ShowWindow(hWndStatusBar, SW_SHOW);
  162.           return 0;
  163.  
  164.         case IDM_SBHIDE:
  165.           bStatusBarVisible = FALSE;
  166.           CheckMenuItem(hMenu, IDM_SBHIDE, MF_CHECKED);
  167.           CheckMenuItem(hMenu, IDM_SBSHOW, MF_UNCHECKED);
  168.           ShowWindow(hWndStatusBar, SW_HIDE);
  169.           return 0;
  170.  
  171.         case IDM_SBDISPLAYTEXT:
  172.           SendMessage(hWndStatusBar, SBM_DISPLAYTEXT, wTextAttributes, (LONG)(LPSTR)SText);
  173.               return 0;
  174.  
  175.           case IDM_SB3DFACE:
  176.           CheckMenuItem(hMenu, wCurrentFaceStyle, MF_UNCHECKED);
  177.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  178.           wCurrentFaceStyle = wParam;
  179.           SendMessage(hWndStatusBar, SBM_FACESTYLE, 0, (LONG)SBFS_3DFACE);
  180.           return 0;
  181.  
  182.           case IDM_SB2DFACE:
  183.           CheckMenuItem(hMenu, wCurrentFaceStyle, MF_UNCHECKED);
  184.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  185.           wCurrentFaceStyle = wParam;
  186.           SendMessage(hWndStatusBar, SBM_FACESTYLE, 0, (LONG)SBFS_2DFACE);
  187.           return 0;
  188.  
  189.           case IDM_SBFLATFACE:
  190.           CheckMenuItem(hMenu, wCurrentFaceStyle, MF_UNCHECKED);
  191.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  192.           wCurrentFaceStyle = wParam;
  193.           SendMessage(hWndStatusBar, SBM_FACESTYLE, 0, (LONG)SBFS_FLATFACE);
  194.           return 0;
  195.  
  196.           case IDM_SBGRAYFACE:
  197.           CheckMenuItem(hMenu, wCurrentFaceColor, MF_UNCHECKED);
  198.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  199.           wCurrentFaceColor = wParam;
  200.           SendMessage(hWndStatusBar, SBM_FACECOLOR, 0, (LONG)SBCLR_GRAY);
  201.           return 0;
  202.  
  203.           case IDM_SBBLACKFACE:
  204.           CheckMenuItem(hMenu, wCurrentFaceColor, MF_UNCHECKED);
  205.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  206.           wCurrentFaceColor = wParam;
  207.           SendMessage(hWndStatusBar, SBM_FACECOLOR, 0, (LONG)SBCLR_BLACK);
  208.           return 0;
  209.  
  210.           case IDM_SBWHITEFACE:
  211.           CheckMenuItem(hMenu, wCurrentFaceColor, MF_UNCHECKED);
  212.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  213.           wCurrentFaceColor = wParam;
  214.           SendMessage(hWndStatusBar, SBM_FACECOLOR, 0, (LONG)SBCLR_WHITE);
  215.           return 0;
  216.  
  217.           case IDM_SBREDFACE:
  218.           CheckMenuItem(hMenu, wCurrentFaceColor, MF_UNCHECKED);
  219.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  220.           wCurrentFaceColor = wParam;
  221.           SendMessage(hWndStatusBar, SBM_FACECOLOR, 0, (LONG)SBCLR_RED);
  222.           return 0;
  223.  
  224.           case IDM_SBGREENFACE:
  225.           CheckMenuItem(hMenu, wCurrentFaceColor, MF_UNCHECKED);
  226.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  227.           wCurrentFaceColor = wParam;
  228.           SendMessage(hWndStatusBar, SBM_FACECOLOR, 0, (LONG)SBCLR_GREEN);
  229.           return 0;
  230.  
  231.           case IDM_SBBLUEFACE:
  232.           CheckMenuItem(hMenu, wCurrentFaceColor, MF_UNCHECKED);
  233.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  234.           wCurrentFaceColor = wParam;
  235.           SendMessage(hWndStatusBar, SBM_FACECOLOR, 0, (LONG)SBCLR_BLUE);
  236.           return 0;
  237.  
  238.         case IDM_SBHELV8:
  239.           CheckMenuItem(hMenu, wCurrentTextFont, MF_UNCHECKED);
  240.           CheckMenuItem(hMenu, wParam, MF_CHECKED);
  241.           wCurrentTextFont = wParam;
  242.           lf.lfHeight = 8;
  243.           lf.lfWidth = 0;          // this field is ignored
  244.           lf.lfEscapement = 0;     // this field is ignored
  245.           lf.lfOrientation = 0;    // this field is ignored
  246.           lf.lfWeight = 0;         // this field is ignor